package br.com.solutions.delivery.controller;

import br.com.solutions.delivery.entity.City;
import br.com.solutions.delivery.entity.Location;
import br.com.solutions.delivery.entity.ZipCode;
import br.com.solutions.delivery.google.GoogleMapsController;
import br.com.solutions.delivery.screen.LocationScreen;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class LocationScreenController {
    
    private static LocationScreenController instance;

    private LocationScreen form;
            
    private Location location;
    
    private class AdicionarLocalActionListener implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                String rua = form.getTxtRua().getText();
                String numero = form.getTxtNumero().getText();
                City city = new City();
                city.setName("Blumenau");
                String estado = form.getTxtEstado().getText();
                String cep = form.getTxtCep().getText();
                location = GoogleMapsController.getLocation(rua, numero, city, estado, cep);
                form.setVisible(false);
            } catch (Exception ex){
                
            }
        }

    }
    private LocationScreenController() {
        this.form = LocationScreen.getInstance();
        this.form.getBtnAdicionarLocal().addActionListener(new AdicionarLocalActionListener());
    }
    
    public static LocationScreenController getInstance(Location location) {
        if (instance == null) {
            instance = new LocationScreenController();
        }
        instance.location = location;
        return instance;
    }
    
    public void showScreen(){
        this.form.setVisible(true);
    }   
    
}
